import org.newdawn.slick.*;

/**
* The Checkbox class is a GUI class for rendering and handling
* a simple check box.
*/
public class Checkbox {

	private int x;
	private int y;
	private int width;
	private int height;
	private Image im1;
	private Image im2;
	private Image im3;
	private Image im4;
	private Font f;
	private String text;
	private ApplicationState parent;
	boolean checked = false;

	public Checkbox(String text, int x, int y, Font f, Image emptyNormal, Image emptyFocus, Image checkedNormal, Image checkedFocus, boolean checked, ApplicationState lb) {

		this.x = x;
		this.y = y;
		this.text = text;
		this.f = f;
		this.im1 = emptyNormal;
		this.im2 = emptyFocus;
		this.im3 = checkedNormal;
		this.im4 = checkedFocus;
		this.checked = checked;

		this.width = im1.getWidth();
		this.height = im1.getHeight();

		parent = lb;
	}

	/**
	* Checks if a click was on the box. If it was, perform some action.
	*/
	public void mousePressed(int button, int mx, int my) {
		if(mx >= x && mx <= x + width && my >= y && my <= y + height) {
			//checked = !checked;
			if (parent instanceof LobbyState) {
				((LobbyState)parent).focusBox(this);
			}
			if (parent instanceof ChatLobbyState)
				((ChatLobbyState)parent).focusBox(this);
		}
	}

	public void switchState() {
		checked = !checked;
	}

	public boolean getState() {
		return checked;
	}

	public void setState(boolean state) {
		checked = state;
	}

	public void render(Graphics g, boolean focused) {
		if(focused)
			g.drawImage((checked ? im4 : im2), x, y);
		else
			g.drawImage((checked ? im3 : im1), x, y);
		g.setFont(f);
		g.setColor(new Color(190,190,190));
		g.drawString(text,x+width+10,y+f.getLineHeight()/2-6);

	}
}